import fas.massload.MassLoader;
import fas.massload.file.LoadFileCreator;
import fas.massload.events.MassLoaderEvent;
import fas.massload.events.MassLoaderErrorEvent;


class Main {
    static function main() { new Main(); }

    function new() {
	trace("Starting Massload...");

	var url1 = "shaks12.txt";

	var url2 = "http://localhost/openhaxechart-branches/version-2-ichor/data-files/line-dot.txt";

	var fake = "hmf?";

        var loader = MassLoader.getInstance();
	var myJson = LoadFileCreator.create({file: url1, name: "json"});
	var myText = LoadFileCreator.create({file: url2, name: "shakespeare"});
	var fake = LoadFileCreator.create({file: url2, name: "fake"});

	// Attaching events
	loader.addEventListener(MassLoaderEvent.COMPLETE_ALL,onCompleteAll);

	myText.addEventListener(MassLoaderErrorEvent.ERROR, onError);
	myText.addEventListener(MassLoaderEvent.COMPLETE, onTextComplete);

	loader.addFile(myText);
	loader.addFile(myJson);
	loader.addFile(fake);

	trace("loader.filesCount: " + loader.filesCount);
	trace("Ending Massload...");
    }

    function onCompleteAll(ev:MassLoaderEvent) : Void {
        trace("The download list is empty!");
    }

    function onError(ev:MassLoaderErrorEvent) : Void {
        trace("Error #" + ev.text);
    }


    function onTextComplete(ev:MassLoaderEvent) : Void {
        trace("Download complete");

        // Trace the text
        trace(ev.file.content.get("json").content.data);
	trace(ev.file.content.get("shakespeare").content.data);
	trace(ev.file.content.get("fake").content.data);
    }
}
